<?php
	include_once(dirname(__FILE__)."/../../mode/person/per_admin.php");
	include_once(dirname(__FILE__)."/../../mode/table/menu.php");
	include_once(dirname(__FILE__)."/../control/getdb.php");
	
	error_reporting(E_ALL ^ E_NOTICE);

	$admin = new per_admin();
	$rs = $admin->getInfo($_COOKIE['snadminName'],$db);
	$adminRights = $rs['adminRights'];

	function writeMenu($adminRights,$father,$db) {
		$menuTable = new menu();
		//print_r($menuTable);
		//global $menuTable;
		$rs = $db->select($menuTable,"fatherId = $father and rightsLevel <= $adminRights",0,1000,'order');
		if($rs[0]){
			foreach($rs as $k=>$v) {
				echo "<item id='".$v['id']."' text='".$v['name']."'>";
				writeMenu($adminRights,$v['id'],$db);
				echo "</item>";
			}
		}
	}


	
	header("Content-type:text/xml");
	echo('<?xml version="1.0" encoding="gb2312" ?>');
	echo("<tree id='0'>");
	writeMenu($adminRights,0,$db);
	echo("</tree>");